package com.supermap.geometrist.toolkit.extend;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import com.alibaba.fastjson.JSONObject;
import com.supermap.geometrist.toolkit.modle.ResponseText;
import com.supermap.services.InterfaceContext;
import com.supermap.services.rest.HttpError;
import com.supermap.services.rest.commontypes.Component;
import com.supermap.services.rest.resources.JaxrsResourceBase;

@Path("/geometrist")
@Component(interfaceClass = GeometristComponent.class)
public class GeometristResource extends JaxrsResourceBase {
    @Path("/toolkit")
    @POST
    @Consumes("application/json")
    public String intersectLineJAXR(String params) {

        String resultsStr = null;
        try {
            InterfaceContext interfaceContext = this.getInterfaceContext();
            GeometristComponent component = interfaceContext.getComponents(GeometristComponent.class).get(0);
            if (params != null) {
                JSONObject paramJSON = JSONObject.parseObject(params);
                resultsStr = component.geometristMethod(paramJSON);
            }
        } catch (Exception e) {
            ResponseText responseText = new ResponseText();
            responseText.setSucceed(false);
            HttpError error = new HttpError();
            error.setErrorMsg("Parameter error,Please check the parameter");
            responseText.setError(error);
            return JSONObject.toJSONString(responseText);
        }
        return resultsStr;
    }
}
